
package edu.upn.sigemfi.plt.converter;

import edu.upn.sigemfi.plt.bc.TipoCuentaDelegate;
import edu.upn.sigemfi.plt.bc.TipoMicroseguroDelegate;
import edu.upn.sigemfi.plt.be.TipoMicroseguro;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

public class TipoMicroseguroConverter implements Converter{

    public Object getAsObject(FacesContext arg0, UIComponent arg1, String string) throws ConverterException {
        TipoMicroseguroDelegate delegado = new TipoMicroseguroDelegate();
        if (string == null) {
            return null;
        }
        try {
            Long codigo = Long.parseLong(string);
            if (codigo != null) {
                return delegado.buscar(codigo);
            } else {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public String getAsString(FacesContext arg0, UIComponent arg1, Object object) throws ConverterException {
        if (object == null) {
            return null;
        }
        if (object instanceof TipoMicroseguro) {
            TipoMicroseguro tipoMicroseguro = (TipoMicroseguro) object;
            return tipoMicroseguro.getIdTipoMicroseguro().toString();
        }
        return null;
    }
 }
